<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 *
 * @author Joker
 * ``sender_uid` int(11) DEFAULT NULL COMMENT '发送者ID',
	`recipient_uid` int(11) DEFAULT 0 COMMENT '接收者ID',
	`action_type` tinyint(1) DEFAULT 0 COMMENT '操作类型 0：普通消息，1：系统通知',
	`source_id` varchar(16) NOT NULL DEFAULT '0' COMMENT '关联 ID',
	`read_flag` tinyint(1) DEFAULT 0 COMMENT '阅读状态',
 */
class Notification extends Model
{
    protected $table="notification";
    
    protected $primaryKey = 'id';
    
    protected $fillable = ['id','sender_uid','recipient_uid','action_type','source_id','read_flag'];
 
    
    /**
     * 一对多获取消息详情
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function moreMsg()
    {
        return $this->hasMany('App\Models\NotificationData','notification_id',$this->primaryKey);
    }
    
    /**
     * 一对一获取用户信息 发送者
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function sender()
    {
        return $this->hasOne('App\User','id','sender_uid');
    }
    
    /**
     * 一对一获取用户信息 接受者
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function recipient()
    {
        return $this->hasOne('App\User','id','recipient_uid');
    }
}